package com.docker.drug.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.docker.drug.domain.DockerDrug;
import com.docker.drug.domain.DoctorDrugInventoryIntermediate;
import com.docker.drug.mapper.DockerDrugMapper;
import com.docker.drug.mapper.DoctorDrugInventoryIntermediateMapper;
import com.docker.drug.mapper.DoctorDrugInventoryMapper;
import com.docker.drug.domain.DoctorDrugInventory;
import com.docker.drug.service.IDoctorDrugInventoryService;

/**
 * 药品盘点Service业务层处理
 * 
 * @author lin
 * @date 2025-04-15
 */
@Service
public class DoctorDrugInventoryServiceImpl implements IDoctorDrugInventoryService 
{
    @Autowired
    private DoctorDrugInventoryMapper doctorDrugInventoryMapper;
    @Autowired
    private DoctorDrugInventoryIntermediateMapper doctorDrugInventoryIntermediateMapper;
    @Autowired
    private DockerDrugMapper dockerDrugMapper;

    /**
     * 查询药品盘点
     * 
     * @param id 药品盘点主键
     * @return 药品盘点
     */
    @Override
    public DoctorDrugInventory selectDoctorDrugInventoryById(Long id)
    {
        return doctorDrugInventoryMapper.selectDoctorDrugInventoryById(id);
    }

    /**
     * 查询药品盘点列表
     * 
     * @param doctorDrugInventory 药品盘点
     * @return 药品盘点
     */
    @Override
    public List<DoctorDrugInventory> selectDoctorDrugInventoryList(DoctorDrugInventory doctorDrugInventory)
    {
        return doctorDrugInventoryMapper.selectDoctorDrugInventoryList(doctorDrugInventory);
    }

    /**
     * 新增药品盘点
     * 
     * @param doctorDrugInventory 药品盘点
     * @return 结果
     */
    @Override
    public int insertDoctorDrugInventory(DoctorDrugInventory doctorDrugInventory)
    {
//        添加药品中间表数据 （ID，盘点单号，药品编码，当前库存）
//        1查询药品列表
        List<DockerDrug> list = dockerDrugMapper.selectDockerDrugList1();
        long count = 1;
        for (DockerDrug dockerDrug : list) {
            DoctorDrugInventoryIntermediate doctorDrugInventoryIntermediate = new DoctorDrugInventoryIntermediate();
            doctorDrugInventoryIntermediate.setId(count++);
            doctorDrugInventoryIntermediate.setInventoryOrder(doctorDrugInventory.getInventoryOrder());
            doctorDrugInventoryIntermediate.setDrugCode(dockerDrug.getDrugCode());
            doctorDrugInventoryIntermediate.setCurrentInventoryQuantity(dockerDrug.getDrugInventory());
            doctorDrugInventoryIntermediateMapper.insertDoctorDrugInventoryIntermediate(doctorDrugInventoryIntermediate);

        }
        return doctorDrugInventoryMapper.insertDoctorDrugInventory(doctorDrugInventory);
    }

    /**
     * 修改药品盘点
     * 
     * @param doctorDrugInventory 药品盘点
     * @return 结果
     */
    @Override
    public int updateDoctorDrugInventory(DoctorDrugInventory doctorDrugInventory)
    {
        return doctorDrugInventoryMapper.updateDoctorDrugInventory(doctorDrugInventory);
    }

    /**
     * 批量删除药品盘点
     * 
     * @param ids 需要删除的药品盘点主键
     * @return 结果
     */
    @Override
    public int deleteDoctorDrugInventoryByIds(Long[] ids)
    {
        return doctorDrugInventoryMapper.deleteDoctorDrugInventoryByIds(ids);
    }

    /**
     * 删除药品盘点信息
     * 
     * @param id 药品盘点主键
     * @return 结果
     */
    @Override
    public int deleteDoctorDrugInventoryById(Long id)
    {
        return doctorDrugInventoryMapper.deleteDoctorDrugInventoryById(id);
    }
}
